package controllers

import (
	"github.com/gin-gonic/gin"
	"github.com/goAdminMicroService/internal/app/products/services"
	"go.uber.org/zap"
	"net/http"
)

type ProductsController struct {
	logger  *zap.Logger
	service services.ProductsService
}

func NewProductsController(logger *zap.Logger, s services.ProductsService) *ProductsController {
	return &ProductsController{logger: logger, service: s}
}

func (pc *ProductsController) Get(c *gin.Context) {
	// 直接返回
	//c.JSON(http.StatusOK, "products hello world")
	//调用service
	p, err := pc.service.Get(c.Request.Context(), 1)
	if err != nil {
		pc.logger.Error("get produce err", zap.Error(err))
		c.String(http.StatusInternalServerError, "%+v", err)
		return
	}
	c.JSON(http.StatusOK, p)
}
